// $Id: handler.h 100 2011-10-21 15:05:36Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef HANDLERS_H_
#define HANDLERS_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/queue.h>

struct niohttp_session;

struct niohttp_request;

typedef int (*niohttp_handler_cb)(
		struct niohttp_session *session,
		struct niohttp_request *req, void *cbarg);

struct niohttp_handler {
	char *pattern;
	size_t len;
	niohttp_handler_cb cb;
	void *cbarg;
	TAILQ_ENTRY(niohttp_handler) entry;
};

TAILQ_HEAD(niohttp_handler_list, niohttp_handler);

int niohttp_handler_compare(
		struct niohttp_handler *a,
		struct niohttp_handler *b);

int niohttp_handler_list_add(struct niohttp_handler_list *handlers,
		const char *pattern, niohttp_handler_cb cb, void *cbarg);

void niohttp_handler_list_del(struct niohttp_handler_list *handlers,
		struct niohttp_handler *entry);

struct niohttp_handler *niohttp_handler_list_find(
		struct niohttp_handler_list *handlers, const char *method);

void niohttp_handler_list_clear(struct niohttp_handler_list *handlers);

#ifdef __cplusplus
}
#endif

#endif /* HANDLERS_H_ */
